package com.map;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

/**
 * @author: csh
 * @Date: 2021/6/29 11:15
 * @Description:HashMap源码学习
 */
public class HashMapStudy {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(2);
        HashMap<Integer,Object> hashMap = new HashMap <>();
        hashMap.put(1,"hong");
//        ConcurrentHashMap<String,Object> concurrentHashMap = new ConcurrentHashMap <>();
//        concurrentHashMap.put("hong",1);

        new Thread("thread1"){
            @Override
            public void run() {
                hashMap.put(7,"B");
                System.out.println(hashMap);
                countDownLatch.countDown();
            }
        }.start();

        new Thread("thread2"){
            @Override
            public void run() {
                hashMap.put(3,"A");
                System.out.println(hashMap);
                countDownLatch.countDown();
            }
        }.start();

        countDownLatch.await();
        System.out.println(hashMap.toString()+"："+hashMap.size());
    }
}
